﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Kakaroto.Pedidos.Preparo
{
    public partial class Bar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Entregue_Click(object sender, EventArgs e)
        {
            GridViewRow row = (GridViewRow)(sender as Control).Parent.Parent;

            Control ct = (Control)(sender as Control);
            while (!(ct is GridView)) ct = ct.Parent;
            GridView gv = (GridView)ct;

            string id = row.Cells[0].Text;

            SqlDataSource.UpdateParameters.Add("Id", id);
            SqlDataSource.UpdateParameters.Add("Status", "1");
            SqlDataSource.Update();

        }

        protected void GridViewCozinha_DataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[1].Text == "&nbsp;")
                {
                    DateTime horaPedido = Convert.ToDateTime(e.Row.Cells[5].Text);
                    TimeSpan tempoDecorrido = DateTime.Now - horaPedido;

                    if (tempoDecorrido.TotalMinutes > 10)
                        e.Row.ForeColor = System.Drawing.Color.Red;
                    else
                        e.Row.ForeColor = System.Drawing.Color.Black;
                }
                else
                {
                    e.Row.ForeColor = System.Drawing.Color.Black;
                }
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            GridViewCozinha.DataBind();
        }
    }
}